home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
EnigmA Amiga Run 1996 June
/
EnigmA AMIGA RUN 08 (1996)(G.R. Edizioni)(IT)[!][issue 1996-06][EARSAN CD VII].iso
/
earcd
/
comm2
/
mmrstrbd.lha
/
MM
/
Rexx
/
MM_RestoreBad.rexx
< prev
next >
Wrap
OS/2 REXX Batch file
|
1996-05-06
|
10KB
|
535 lines
/*
$VER: MM_RestoreBad 0.16 (06.05.96)
(C) 1996 Robert Hofmann
*/
parse arg args
options cache
options failat 99
options results
signal on break_c
signal on break_d
signal on break_e
signal on break_f
signal on halt
signal on ioerr
signal on syntax
address 'MAILMANAGER'
Main:
call Init
call Header
call Parse_Args(strip(args))
Show
if system.arg.gui then call GUI
call Search_Msgs
if system.msgs.count=0 then call Quit(6, 'No msgs selected!!!')
call Restore_Msgs
call Quit(0, 'All done.')
exit
Add_Export: procedure Expose system.
arg area
if find(system.export, area)>0 then return
system.export = system.export area
MM_AddToStem 'system.export' 'area'
return
Add_Msg: procedure Expose found.
parse arg nr, area, . 'PATH: ' path
if length(path)>30 then parse value right(path, 30) with . path
path = strip(path)
MM_AddToStem 'found.msg' 'nr'
MM_AddToStem 'found.area' 'area'
MM_AddToStem 'found.path' 'path'
found.maxlen = max(found.maxlen, length(area)+1)
found.count = found.msg.count
return
Add_Msg_Req: procedure Expose ask. found.
parse arg nr
tmp = left(found.area.nr',', found.maxlen) right(found.msg.nr, 4)': 'found.path.nr
MM_AddToStem 'ask' 'tmp'
return
break_c:; break_d:; break_e:; break_f:; halt:
signal off break_c
signal off break_d
signal off break_e
signal off break_f
signal off halt
return_code = 5
error_line = 0
error_msg = 'Execution halted!!!'
rc = 0
signal Exit
Exit:
select
when return_code>=40 then error = 'INTERNAL-ERROR:'
when return_code>=30 then error = 'IO-ERROR:'
when return_code>=20 then error = 'ERROR:'
when return_code>=10 then error = 'WARNING:'
when return_code>=5 then error = 'INFO:'
otherwise error = ''
end
if return_code>5 & ~system.arg.noreq then
call Request_Choice('\c\n'error'\n\n ' error_msg ' \n', '* _OK ', '_')
call Log()
call Log('***' strip(error error_msg) '***', '+')
call Log(,'\')
call setclip('MM_LogPre', system.mm.logpre)
exit return_code
Get_Arg: procedure Expose args system.
arg keyword, mode, old
uargs = upper(args)
p = find(uargs, keyword)
if p=0 then
do
p = pos(' 'keyword'=', ' 'uargs)
if p>0 then args = overlay(' ', args, p+length(keyword))
p = find(upper(args), keyword)
end
system.cmdopt.keyword = p>0
select
when mode=0 then
if p>0 then
do
ret = 1
args = delword(args, p, 1)
end
else ret = old
when mode=1 then
if p>0 then
do
left = subword(args, 1, p-1)
rest = subword(args, p+1)
if left(rest, 1)='"' then parse var rest . '"' ret '"' rest
else parse var rest ret rest
args = strip(left strip(rest))
end
else ret = old
when mode=2 then
do
if left(args, 1)='"' then parse var args . '"' ret '"' args
else parse var args ret args
if strip(ret)='' then ret = old
end
otherwise exit 99
end
args = strip(args)
ret = strip(ret, 'b', '" ')
return ret
Get_Version: procedure
parse arg mode
parse value sourceline(3-mode) with . . ver .
parse var ver tst 'ß' .
if ~datatype(strip(tst, 'b', '/ce '), 'N') then
if ~mode then ver = Get_Version(1)
else exit 99
return ver
GUI: procedure Expose system.
call Log('Scanning' system.mm.badarea'...')
MM_SearchMsgs system.mm.badarea 'msgs' '#?' '#?' '#?' '!DEL' '!MARK' 'UNLNKNODE'
found. = 0
do n=0 to msgs.count-1
MM_ReadMsg system.mm.badarea msgs.n 'msg'
if RC>0 then iterate
parse var msg.head.0 . 'AREA:' real_area .
tmp = msg.foot.count-1
call Add_Msg(msgs.n, real_area, msg.foot.tmp)
end
ask. = 0
do n=0 to found.count-1
call Add_Msg_Req(n)
end
MM_SortStem 'ask'
ret. = 0
MM_MultiSelReq 'ask' 'ret' '"Select msgs to restore"' 'STR'
if ret.count=0 then call Quit(5, 'Aborted by user!')
call Log('Marking msgs...')
mark = 'MARK'
do n=0 to ret.count-1
parse var ret.n . ',' nr .
MM_EditMsgFlags system.mm.badarea nr 'mark'
end
return
Header:
call Log(,'/')
call Log('***' system.prg.id '***', '+')
call Log(' 'system.prg.cr)
call Log()
return
Init:
system. = 0
MM_GetTaskPri 'system.taskpri'
call pragma('p', system.taskpri)
system.prg.ver = Get_Version(0)
system.prg.name = 'MM_RestoreBad'
system.prg.id = system.prg.name 'v'system.prg.ver
system.prg.cr = '(C) 1996 Robert Hofmann'
system.tmpfile = 'T:'system.prg.name'.tmp'
system.mm.logpre = getclip('MM_LogPre')
system.prg.logpre = system.mm.logpre'|'
call setclip('MM_LogPre', system.prg.logpre)
system.cmdopts = 'BADAREA/A,MSG/K/N,MARKED/S,GUI/S,NOREQ/S,EXPORT/S'
system.warn = '*** WARNING:'
MM_Version 'system.mm'
MM_GetAreas 'system.mm' 'BAD'
system.mm.badarea = system.mm.0
if system.mm.release<445 then call Quit(10, 'Sorry, you need MM >= v1.2.445 to use this script!')
call Include_Lib('rexxsupport')
return
Include_Lib: procedure Expose system.
parse arg lib, prio
if right(upper(lib), 8)~='.LIBRARY' then lib = lib'.library'
if prio='' then prio = 0
if ~show('l', lib) then
if ~addlib(lib, prio, -30, 0) then call Quit(20, 'Could not open' lib'!!!')
return
IOerr:
signal off ioerr
return_code = 20
error_line = sigl
error_msg = 'IO-error' rc 'at line' sigl '['errortext(rc)']')
rc = 0
signal Exit
Log: procedure Expose system.
parse arg text, pre
tmp = word('PRG MM', (pre~='')+1)
text = system.tmp.logpre || pre' 'text
MM_WriteLog 'text' '2'
return
Parse_Args: procedure Expose system.
parse arg args
tpl = system.cmdopts',?/S'
args = translate(args, ' ', '9'x)
pk = pos('/K', tpl)
ps = pos('/S', tpl)
select
when pk=0 & ps=0 then p = 0
when pk=0 & ps>0 then p = ps
when ps=0 & pk>0 then p = pk
otherwise p = min(pk, ps)
end
p = lastpos(',', left(tpl, p))
tpl = substr(tpl',', p+1) || left(tpl, max(p-1, 0))
do while tpl~=''
parse var tpl template ',' tpl
parse var template keyword '/' .
bool = pos('/S', template)>0
key = pos('/K', template)>0
must = pos('/A', template)>0
num = pos('/N', template)>0
select
when must then system.arg.keyword = '0'x
when bool then system.arg.keyword = 0
when num then system.arg.keyword = 0
otherwise system.arg.keyword = ''
end
if bool | key then mode = ~bool
else mode = 2
system.arg.keyword = Get_Arg(keyword, mode, system.arg.keyword)
if must & system.arg.keyword='0'x then
do
tmp = template 'missing!!!'
say
say ' ***' tmp '***'
signal Usage
end
if num & ~datatype(system.arg.keyword, 'N') & ~must & system.arg.keyword~='' then
do
tmp = 'Numeric value expected for' template', but is "'system.arg.keyword'"!!!'
say
say ' ***' tmp '***'
signal Usage
end
end
tmp = '?'; if system.arg.tmp then signal Usage
if args~='' then call Quit(10, 'Unknown option(s):' args)
if upper(system.mm.badarea)~=upper(system.arg.badarea) then call Quit(5, system.arg.badarea 'is not your #BADAREA!')
if system.arg.gui & system.arg.msg>0 then call Quit(11, 'You must not use GUI/S together with MSG/K/N')
if system.arg.marked & system.arg.msg>0 then call Quit(12, 'You must not use MARKED/S together with MSG/K/N')
if system.arg.msg=0 & ~system.arg.marked & ~system.arg.gui then call Quit(13, 'Too few arguments!!!')
return
Quit:
parse arg return_code, error_msg
error_line = 0
rc = 0
signal Exit
Replace: procedure
parse arg string,new,old
do while index(string, old) ~= 0
interpret "parse var string l '"old"' r"
string = l || new || r
end
return string
Request_Choice: procedure Expose system.
parse arg text, buttons, ret_vals
title = system.prg.name'-Requester'
text = translate(Replace(text, '0A'x, '\n'), '1b'x, '\')
if length(text)<40 then text = center(text, 40)
MM_Requester title 'text' 'buttons'
if rc=0 then rc=words(ret_vals)
return compress(word(ret_vals, rc), '_')
Restore_Msgs: procedure Expose system.
if system.arg.msg=0 then
if ~Request_Choice('\c\n Restore selected msg(s)? \n', '* _YES | _NO ', '1 0') then
call Quit(5, 'Aborted by user!')
bad = system.mm.badarea
system.export = ''
do n=0 to system.msgs.count-1
nr = system.msgs.n
MM_ReadMsg bad nr 'msg'
if RC>0 then
do
call Warn_Req('Msg #'nr 'does not exist!')
iterate
end
parse var msg.head.0 . 'AREA:' real_area .
MM_GetAreaInfo real_area 'real'
if RC>0 then
do
call Warn_Req(real_area 'does not exist!')
iterate
end
txt = bad', msg #'nr 'to' real_area
MM_MoveMsg bad nr real_area
if RC>0 then
do
call Warn_Req('Unable to restore' txt'!')
iterate
end
call Add_Export(real_area)
call Log('Restored' txt'.')
end
if ~system.arg.noreq & ~system.arg.export then
exp = Request_Choice('\c\nExport processed areas?\n', '* _YES | _NO ', '1 0')
else exp = 0
if system.arg.export | exp then
do
MM_SortStem 'system.export'
do n=0 to system.export.count-1
call Log(' Exporting area' system.export.n'...')
MM_Export system.export.n
end
end
call Log(' Cleaning' bad'...')
MM_CleanArea bad
return
Search_Msgs: procedure Expose system.
if system.arg.msg>0 then
do
MM_AddToStem 'system.msgs' 'system.arg.msg'
return
end
call Log('Searching for marked msgs...')
MM_SearchMsgs system.mm.badarea 'system.msgs' '#?' '#?' '#?' 'MARK'
return
Syntax:
signal off syntax
return_code = 40
error_line = sigl
error_msg = 'Syntax-error' rc 'at line' sigl '['errortext(rc)']'
rc = 0
signal Exit
Usage:
rx. = ''
rx.0.0 = '[rx] '
rx.0.1 = '[.rexx]'
m = pos('/e', system.prg.ver)>0
tmp = rx.m.0 || system.prg.name || rx.m.1
say
say 'Usage:' tmp system.cmdopts
say
call Quit(0, 'Usage requested.')
Warn_Req: procedure Expose system.
parse arg text
if ~system.arg.noreq then call Request_Choice('\c\n'system.warn'\n\n'text'\n', '* _OK ', '_')
call Log(system.warn text)
return